home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Python / frozenmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  1.4 KB  |  79 lines

  1. /* Python interpreter main program for frozen scripts */
  2.  
  3. #include "Python.h"
  4.  
  5. #ifdef MS_WIN32
  6. extern void PyWinFreeze_ExeInit();
  7. extern void PyWinFreeze_ExeTerm();
  8. extern int PyInitFrozenExtensions();
  9. #endif
  10.  
  11. #ifdef HAVE_UNISTD_H
  12. #include <unistd.h> /* For isatty() */
  13. #endif
  14.  
  15. /* For isatty()'s proto. - [cjh] */
  16. #ifdef HAVE_UNISTD_H
  17. #include <unistd.h>
  18. #endif
  19.  
  20. /* Main program */
  21.  
  22. int
  23. Py_FrozenMain(argc, argv)
  24.     int argc;
  25.     char **argv;
  26. {
  27.     char *p;
  28.     int n, sts;
  29.     int inspect = 0;
  30.     int unbuffered = 0;
  31.  
  32.     Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
  33.  
  34.     if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
  35.         inspect = 1;
  36.     if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
  37.         unbuffered = 1;
  38.  
  39.     if (unbuffered) {
  40.         setbuf(stdin, (char *)NULL);
  41.         setbuf(stdout, (char *)NULL);
  42.         setbuf(stderr, (char *)NULL);
  43.     }
  44.  
  45. #ifdef MS_WIN32
  46.     PyInitFrozenExtensions();
  47. #endif /* MS_WIN32 */
  48.     Py_SetProgramName(argv[0]);
  49.     Py_Initialize();
  50. #ifdef MS_WIN32
  51.     PyWinFreeze_ExeInit();
  52. #endif
  53.  
  54.     if (Py_VerboseFlag)
  55.         fprintf(stderr, "Python %s\n%s\n",
  56.             Py_GetVersion(), Py_GetCopyright());
  57.  
  58.     PySys_SetArgv(argc, argv);
  59.  
  60.     n = PyImport_ImportFrozenModule("__main__");
  61.     if (n == 0)
  62.         Py_FatalError("__main__ not frozen");
  63.     if (n < 0) {
  64.         PyErr_Print();
  65.         sts = 1;
  66.     }
  67.     else
  68.         sts = 0;
  69.  
  70.     if (inspect && isatty((int)fileno(stdin)))
  71.         sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
  72.  
  73. #ifdef MS_WIN32
  74.     PyWinFreeze_ExeTerm();
  75. #endif
  76.     Py_Finalize();
  77.     return sts;
  78. }
  79.